{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 万有引力计算器\n",
    "m1 = int(input('m1: '))\n",
    "m2 = int(input('m2: '))\n",
    "d = int(input('d: '))\n",
    "G = 6.67e-11\n",
    "F = G*m1*m2/(d*d)\n",
    "print(F)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n"
     ]
    }
   ],
   "source": [
    "# 质数的距离\n",
    "# a\n",
    "n = 1000\n",
    "primes = []\n",
    "for i in range(3, n+1):\n",
    "    status = True\n",
    "    for j in range(2, i):\n",
    "        if i % j == 0:\n",
    "            status = False\n",
    "            break\n",
    "    if status:\n",
    "        primes.append(i)\n",
    "print(primes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 2, 4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2, 4, 14, 4, 6, 2, 10, 2, 6, 6, 4, 6, 6, 2, 10, 2, 4, 2, 12, 12, 4, 2, 4, 6, 2, 10, 6, 6, 6, 2, 6, 4, 2, 10, 14, 4, 2, 4, 14, 6, 10, 2, 4, 6, 8, 6, 6, 4, 6, 8, 4, 8, 10, 2, 10, 2, 6, 4, 6, 8, 4, 2, 4, 12, 8, 4, 8, 4, 6, 12, 2, 18, 6, 10, 6, 6, 2, 6, 10, 6, 6, 2, 6, 6, 4, 2, 12, 10, 2, 4, 6, 6, 2, 12, 4, 6, 8, 10, 8, 10, 8, 6, 6, 4, 8, 6, 4, 8, 4, 14, 10, 12, 2, 10, 2, 4, 2, 10, 14, 4, 2, 4, 14, 4, 2, 4, 20, 4, 8, 10, 8, 4, 6, 6, 14, 4, 6, 6, 8, 6]\n"
     ]
    }
   ],
   "source": [
    "# b\n",
    "distances = []\n",
    "for k in range(1, len(primes)):\n",
    "    distances.append(primes[k] - primes[k-1])\n",
    "print(distances)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最大值:  20\n",
      "最小值:  2\n",
      "平均值:  5.9879518072289155\n",
      "方差:  12.505878937436492\n"
     ]
    }
   ],
   "source": [
    "# c\n",
    "def my_min(ps):\n",
    "    the_min = ps[0]\n",
    "    for p in ps:\n",
    "        if p < the_min:\n",
    "            the_min = p\n",
    "    return the_min\n",
    "def my_max(ps):\n",
    "    the_max = ps[0]\n",
    "    for p in ps:\n",
    "        if p > the_max:\n",
    "            the_max = p\n",
    "    return the_max\n",
    "def my_avg(ps):\n",
    "    the_sum = 0\n",
    "    for p in ps:\n",
    "        the_sum += p\n",
    "    return the_sum / len(ps)\n",
    "def fangcha(ps):\n",
    "    the_sum = 0\n",
    "    avg = my_avg(ps)\n",
    "    for p in ps:\n",
    "        the_sum += (avg-p)**2\n",
    "    return the_sum / len(ps)\n",
    "\n",
    "print('最大值: ', my_max(distances))\n",
    "print('最小值: ', my_min(distances))\n",
    "print('平均值: ', my_avg(distances))\n",
    "print('方差: ', fangcha(distances))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "超平均距离个数:  91\n"
     ]
    }
   ],
   "source": [
    "avg = my_avg(distances)\n",
    "count = 0\n",
    "for d in distances:\n",
    "    if d > avg:\n",
    "        count += 1\n",
    "print('超平均距离个数: ', count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['T', 'A', 'T', 'G', 'A', 'A', 'G', 'T', 'C', 'C', 'C', 'C', 'A', 'A', 'T', 'C', 'A', 'T', 'C', 'A', 'C', 'G', 'G', 'A', 'C', 'C', 'C', 'T', 'C', 'T', 'C', 'A', 'A', 'G', 'A', 'G', 'T', 'T', 'C', 'T', 'C', 'G', 'A', 'C', 'T', 'G', 'G', 'C', 'A', 'A', 'G', 'C', 'A', 'T', 'T', 'T', 'C', 'C', 'C', 'C', 'G', 'G', 'T', 'G', 'A', 'T', 'G', 'T', 'T', 'A', 'G', 'G', 'C', 'G', 'A', 'C', 'C', 'A', 'T', 'A', 'T', 'A', 'T', 'G', 'G', 'A', 'G', 'C', 'C', 'T', 'G', 'A', 'G', 'A', 'G', 'C', 'A', 'C', 'C', 'C', 'T', 'A', 'G', 'C', 'A', 'A', 'G', 'A', 'T', 'A', 'T', 'C', 'C', 'A', 'A', 'A', 'G', 'A', 'C', 'A']\n",
      "['A', 'T', 'A', 'C', 'T', 'T', 'C', 'A', 'G', 'G', 'G', 'G', 'T', 'T', 'A', 'G', 'T', 'A', 'G', 'T', 'G', 'C', 'C', 'T', 'G', 'G', 'G', 'A', 'G', 'A', 'G', 'T', 'T', 'C', 'T', 'C', 'A', 'A', 'G', 'A', 'G', 'C', 'T', 'G', 'A', 'C', 'C', 'G', 'T', 'T', 'C', 'G', 'T', 'A', 'A', 'A', 'G', 'G', 'G', 'G', 'C', 'C', 'A', 'C', 'T', 'A', 'C', 'A', 'A', 'T', 'C', 'C', 'G', 'C', 'T', 'G', 'G', 'T', 'A', 'T', 'A', 'T', 'A', 'C', 'C', 'T', 'C', 'G', 'G', 'A', 'C', 'T', 'C', 'T', 'C', 'G', 'T', 'G', 'G', 'G', 'A', 'T', 'C', 'G', 'T', 'T', 'C', 'T', 'A', 'T', 'A', 'G', 'G', 'T', 'T', 'T', 'C', 'T', 'G', 'T']\n"
     ]
    }
   ],
   "source": [
    "# 基因\n",
    "import random\n",
    "dna1 = []\n",
    "for i in range(120):\n",
    "    dna1.append(random.choice('AGCT'))\n",
    "print(dna1)\n",
    "dna2 = []\n",
    "for jianji in dna1:\n",
    "    if jianji == 'A':\n",
    "        dna2.append('T')\n",
    "    elif jianji == 'T':\n",
    "        dna2.append('A')\n",
    "    elif jianji == 'C':\n",
    "        dna2.append('G')\n",
    "    elif jianji == 'G':\n",
    "        dna2.append('C')\n",
    "print(dna2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "指定一个长度: 10\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['G', 'G', 'C', 'A', 'G', 'A', 'G', 'C', 'T', 'C']\n",
      "['C', 'C', 'G', 'T', 'C', 'T', 'C', 'G', 'A', 'G']\n",
      "DNA1 A: 2\n",
      "DNA1 G: 4\n",
      "DNA1 C: 3\n",
      "DNA1 T: 1\n",
      "DNA2 A: 1\n",
      "DNA2 G: 3\n",
      "DNA2 C: 4\n",
      "DNA2 T: 2\n"
     ]
    }
   ],
   "source": [
    "dna1 = []\n",
    "for i in range(int(input('指定一个长度:'))):\n",
    "    dna1.append(random.choice('AGCT'))\n",
    "print(dna1)\n",
    "dna2 = []\n",
    "a1 = 0\n",
    "t1 = 0\n",
    "c1 = 0\n",
    "g1 = 0\n",
    "a2 = 0\n",
    "t2 = 0\n",
    "c2 = 0\n",
    "g2 = 0\n",
    "for jianji in dna1:\n",
    "    if jianji == 'A':\n",
    "        a1 += 1\n",
    "        t2 += 1\n",
    "        dna2.append('T')\n",
    "    elif jianji == 'T':\n",
    "        t1 += 1\n",
    "        a2 += 1\n",
    "        dna2.append('A')\n",
    "    elif jianji == 'C':\n",
    "        c1 += 1\n",
    "        g2 += 1\n",
    "        dna2.append('G')\n",
    "    elif jianji == 'G':\n",
    "        g1 += 1\n",
    "        c2 += 1\n",
    "        dna2.append('C')\n",
    "print(dna2)\n",
    "print('DNA1 A:', a1)\n",
    "print('DNA1 G:', g1)\n",
    "print('DNA1 C:', c1)\n",
    "print('DNA1 T:', t1)\n",
    "print('DNA2 A:', a2)\n",
    "print('DNA2 G:', g2)\n",
    "print('DNA2 C:', c2)\n",
    "print('DNA2 T:', t2)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
